<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>

<html>
<head>
<%@include file="/common/meta.jsp"%>
<script type="text/javascript">
jQuery.noConflict();
</script>
<%@include file="/common/calendar.jsp"%>
<%@include file="/common/ec.jsp"%>
<%@include file="/common/dwr.jsp"%>
<script type="text/javascript"	src="${ctx}/dwr/interface/CatalogDwrAction.js"></script>
<script type="text/javascript" src="${ctx}/dwr/interface/ArticleAction.js"></script>
<title>内容管理</title>
<script type="text/javascript">
function onRemove() {
    var sels = document.getElementsByTagName('input');
    var checked = false;;
    for(i = 0; i < sels.length; i++) {
        if(sels[i].id == 'selectedItems' && sels[i].checked) {
           checked = true;
           break;
        }
    } 
    if(!checked) {
        alert('请至少选择一条记录。');
        return;
    }
    
    if(confirm("您确定删除此篇内容吗？")) {
       var articles = new Array();
       var j=0;
	    for (var i = 0; i < sels.length; i ++) {
	    	if (sels[i].checked) {
	    		articles[j]=sels[i].value;
	    		j++;
	    	}
	    }
	  ArticleAction.removeArticle(articles,function(result){
			if(result.id == "1"){
				alert("你选择的记录: '"+result.name+"' 已审核通过,不能删除!");
			} else{
			   window.location="listArticles.do?type=${type}";
			}
		});
    } else {
       return false;
    }
}
function onQuery() {
	$("frmQuery").action = "listArticles.do?type=${type}";
	$("frmQuery").submit();
}
/** set parentId */
		function setCatalog(){
			CatalogDwrAction.getCatalog("catalog","1",function(catalog){
				DWRUtil.removeAllOptions("catalogId");
				DWRUtil.addOptions($("catalogId"), catalog,
		    		function getValue(catalog) {
		    			return catalog.id;
		    		},
		    		function getText(catalog) {
		    			return catalog.text;
		    		});
		    		
			DWRUtil.setValue("catalogId", "${catalogId}");
				} 
			);
		}
		setCatalog();
</script>
</head>


<body>
<div class="x-panel">
<div class="x-panel-header">${type eq 0?'文章':null}${type eq 1?'图片':null}${type eq 2?'视频':null}管理
</div>

<div class="x-toolbar">
<table width="99%" border="0">
	<tr>
		<td>
			<s:form name="frmQuery" id="frmQuery" method="post">
			<s:hidden name="type"></s:hidden>
			  <table border="0">
				<tr>
					<td>
							<a href="${ctx}/admin/article/newArticle.do?type=0">
							<img src="${ctx}/images/icons/add.gif" />添加</a>
							<!-- 
							<a href="${ctx}/admin/article/newImage.do?type=1">
							<img src="${ctx}/images/icons/add.gif" />添加图片</a>
							<a href="${ctx}/admin/article/newVideo.do?type=2">
							<img src="${ctx}/images/icons/add.gif" />添加视频</a>
							 -->
					</td>
					<td><span class="ytb-sep"></span></td>
					<td>
						<a href="#" onclick="onRemove()">
						<img src="${ctx}/images/icons/delete.gif" />删除</a>
					</td>
					<td><span class="ytb-sep"></span></td>
					<td>
						<img src="${ctx}/images/icons/article_go.gif" class="icon">
						<a href="${ctx}/admin/article/orderArticle.do" target="main">排序</a>
					</td>
					<td><span class="ytb-sep"></span></td>
					<td>
					  标题：<input type="text" name="articleName" value="${articleName}" style="width:100px"/>&nbsp;
					</td>
					<td>
					  所属栏目：<select id="catalogId" name="catalogId"></select>
					</td>
					<td>
						从：
						<input type="text" id="beginDate" name="beginDate" popupDateFormat="yyyy-MM-dd"
						style="width:110px;"
						class="Wdate" onfocus="WdatePicker({skin:'whyGreen'})" value='<s:date name="beginDate" format="yyyy-MM-dd"/>'/>
						到：
						<input type="text" id="endDate" name="endDate" popupDateFormat="yyyy-MM-dd"
						style="width:110px;" 
						class="Wdate"  onfocus="WdatePicker({minDate:'#F{$dp.$D(\'beginDate\')}',skin:'whyGreen'})" value='<s:date name="endDate" format="yyyy-MM-dd"/>'/>
					</td>
					<td>
						<input type="submit" value="查 询" class="button" onclick="onQuery()" />
					</td>
				</tr>
			  </table>
			</s:form>
		</td>
		</tr>
</table>
</div>
<div class="x-panel-body">
<div style="margin-left:-3px;" align="center">
	<ec:table items="items" var="item" retrieveRowsCallback="limit" sortRowsCallback="limit" 
		action="listArticles.do" 
		useAjax="false"
		doPreload="false" 
		pageSizeList="20,50,100" 
		editable="false"
		sortable="true" 
		rowsDisplayed="20"
		generateScript="true" 
		resizeColWidth="true" 
		classic="true" 
		width="100%"
		minHeight="400"
		toolbarContent="navigation|pagejump|pagesize|refresh|extend|status">
	<ec:row>
		<ec:column width="20" property="_s_count" title="序号" value="${GLOBALROWCOUNT}" style="text-align:center" sortable="false"/>
		<ec:column width="30" property="_s" title="选择" style="text-align:center" sortable="false">
			<c:if test="${item.audited eq 1}">
				<input type="checkbox" name="selectedItems" id="selectedItems" value="${item.id}" disabled="disabled" style="border:0px;"/>
			</c:if>
			<c:if test="${item.audited eq 0}">
				<input type="checkbox" name="selectedItems" id="selectedItems" value="${item.id}" style="border:0px;"/>
			</c:if>
		</ec:column>
		<ec:column width="330" property="title" ellipsis="true" title="文章标题" sortable="false">
			<a href="${ctx}${item.path}" target="_blank" title="查看详细信息"><font color="blue">${item.title}</font></a>
		</ec:column>
		<ec:column width="80" property="author" title="作者"  sortable="false"/>
		<ec:column width="90" property="catalog.name" title="所属栏目" sortable="false" />
		<ec:column width="60" property="category" title="文章类别"	sortable="false" style="text-align:center">
			<c:if test="${item.category eq 0}">
				<img src="${ctx}/images/icons/article.gif" title="文章"/>
			</c:if>
			<c:if test="${item.category eq 1}">
				<img src="${ctx}/images/icons/image.png" title="图片"/>
			</c:if>
			<c:if test="${item.category eq 2}">
				<img src="${ctx}/images/icons/expand.gif" title="视频"/>
			</c:if>
		</ec:column>
		<ec:column width="90" style="text-align:center" property="createTime" cell="date" title="发布时间" sortable="false" />
		<ec:column width="50" style="text-align:center" property="audited" title="审核" sortable="false"	>
			<c:if test="${item.audited eq 1}">
				<img src="${ctx}/images/icons/accept.gif" title="已审核"/>
			</c:if>
			<c:if test="${item.audited eq 0}">
				<img src="${ctx}/images/icons/stop.gif" title="未审核"/>
			</c:if>
		</ec:column>
		<ec:column width="50" property="_0" title="编辑" style="text-align:center" sortable="false">
			<c:if test="${item.category eq '0'}">
				<a href="editArticle.do?model.id=${item.id}&type=${item.category}"> 
				<img src="${ctx}/images/icons/modify.gif" border="0" title="编辑" /></a>
			</c:if>
			<c:if test="${item.category eq '1'}">
				<a href="editImage.do?model.id=${item.id}&type=${item.category}"> 
				<img src="${ctx}/images/icons/modify.gif" border="0" title="编辑" /></a>
			</c:if>
			<c:if test="${item.category eq '2'}">
				<a href="editVideo.do?model.id=${item.id}&type=${item.category}"> 
				<img src="${ctx}/images/icons/modify.gif" border="0" title="编辑" /></a>
			</c:if>
		</ec:column>
	</ec:row>
</ec:table></div>

</div>
</div>
</body>
</html>

